package com.heima.kafka.controller;

import com.alibaba.fastjson.JSON;
import com.heima.kafka.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * create 2023/6/23 10:50
 */


@RestController
public class HelloController {

    @Autowired
    private KafkaTemplate<String,String> kafkaTemplate;
    @GetMapping("/hello")
    public String hello() {
//        kafkaTemplate.send("heima", "你好，kafka");

        User user = new User(23,"张三");
        String json = JSON.toJSONString(user);
        kafkaTemplate.send("heima",json);
        return "hello kafka";
    }


}
